package cn.book.bus.utils;



import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;


import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;


public class FetchProxyIpUtil {



    public static List<String>  getProxyIp() throws IOException {
        ArrayList<String> proxyIpList = new ArrayList<>();
//        List<String> proxyIpList = Lists.newArrayList();
        //解析网页（jsoup返回document就是浏览器document对象）
        Document document = Jsoup.parse(new URL("http://www.xiladaili.com/gaoni/"), 60000);
        Element body = document.selectFirst(".fl-table > tbody:nth-child(2)");
        Elements tr = body.getElementsByTag("tr");
        for(Element r : tr){
            Elements td = r.getElementsByTag("td");
            if(CollectionUtils.isNotEmpty(td)){
                Element element = td.get(0);
                String proxyIp = element.text();
                proxyIpList.add(proxyIp);
            }
        }
        return proxyIpList;
    }

    public static void main(String[] args) throws IOException {

        System.out.println("2222222"+getProxyIp());
    }

}

